package cn.com;

import cn.com.ui.LifeBkActivity;
import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.RadioButton;
import android.widget.TabHost;

public class TabHostMain extends TabActivity {

	private TabHost tabHost;
	private RadioButton main_tab_msg, main_tab_friends, main_tab_lifeBk,main_tab_set,
	main_tab_sh;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.tabmain);
		initTab();
		init();
		
	}
	private void init() {
		main_tab_msg=(RadioButton)findViewById(R.id.main_tab_home);
		main_tab_friends = (RadioButton) findViewById(R.id.main_tab_friends);
		main_tab_set = (RadioButton) findViewById(R.id.main_tab_set);
		main_tab_lifeBk = (RadioButton) findViewById(R.id.main_tab_lifebk);
		main_tab_sh = (RadioButton) findViewById(R.id.main_tab_sh);
		
		// 改变初始化选项卡设置
//		tabHost.setCurrentTab(2);
//		main_tab_car.setChecked(true);
		String getIntent= getIntent().getStringExtra("main_tab_name");
		if("AddFriendsActivity".equals(getIntent) || "FriendsCircleActivity".equals(getIntent) ){
			tabHost.setCurrentTab(1);
			main_tab_friends.setChecked(true);
		}else if("SendShActivity".equals(getIntent)){
			tabHost.setCurrentTab(3);
			main_tab_sh.setChecked(true);
		}
		

		main_tab_msg.setOnClickListener(new OnClickListener() {

			public void onClick(View view) {
				tabHost.setCurrentTabByTag("msg");

			}
		});
		
		main_tab_friends.setOnClickListener(new OnClickListener() {

			public void onClick(View view) {
				tabHost.setCurrentTabByTag("friends");

			}
		});
		main_tab_lifeBk.setOnClickListener(new OnClickListener() {
			
			public void onClick(View view) {
				tabHost.setCurrentTabByTag("lifebk");
				
			}
		});
		
		main_tab_sh.setOnClickListener(new OnClickListener() {
			
			public void onClick(View view) {
				tabHost.setCurrentTabByTag("sh");
				
			}
		});
		
		
		main_tab_set.setOnClickListener(new OnClickListener() {

			public void onClick(View view) {
				tabHost.setCurrentTabByTag("set");

			}
		});
	
		
		
		
	}
	private void initTab() {
		tabHost = getTabHost();
		tabHost.addTab(tabHost.newTabSpec("msg").setIndicator("msg")
				.setContent(new Intent(this,MsgActivity.class)));
		
		tabHost.addTab(tabHost.newTabSpec("friends").setIndicator("friends")
				.setContent(new Intent(this, FriendsActivity.class)));
	
		tabHost.addTab(tabHost.newTabSpec("lifebk").setIndicator("lifebk")
				.setContent(new Intent(this, LifeBkActivity.class)));
		
		tabHost.addTab(tabHost.newTabSpec("sh").setIndicator("sh")
				.setContent(new Intent(this, ShActivity.class)));
		
		tabHost.addTab(tabHost.newTabSpec("set").setIndicator("set")
				.setContent(new Intent(this, SetActivity.class)));
//	
	}
	
	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		// TODO Auto-generated method stub
		if(keyCode == KeyEvent.KEYCODE_BACK){
			finish();
		}
		return super.onKeyDown(keyCode, event);
	}

}
